#include "log.h"

Logger::Logger(const char *file, const char *func, int line, LoggerOutFunc out)
{
    file_ = file;
    func_ = func;
    line_ = line;
    out_ = out;
}

Logger::~Logger()
{
    out_(*this);
}

const char *Logger::GetFile()
{
    return file_;
}

const char *Logger::GetFunc()
{
    return func_;
}

const int Logger::GetLine()
{
    return line_;
}

Logger &Printf(Logger &logger)
{
    printf("\033[31m%s\033[0m<\033[34m%d\033[0m>: \033[32m%s\033[0m\n",
           logger.GetFunc(), logger.GetLine(), logger.str().c_str());
    return logger;
}

Logger &OuterPrintf(Logger &logger)
{
    printf("\n%d.\033[36m%s\033[0m\n", logger.GetLine(), logger.str().c_str());
    return logger;
}

Logger &CodePrintf(Logger &logger)
{
    printf("\n    \033[31m%s\033[0m<\033[34m%d\033[0m>: exec>  \033[32m%s\033[0m\n",
           logger.GetFunc(), logger.GetLine(), logger.str().c_str());
    return logger;
}

Logger &InnerPrintf(Logger &logger)
{
    printf("        %d.\033[33m%s\033[0m\n", logger.GetLine(), logger.str().c_str());
    return logger;
}

Logger &HorizontalLine(Logger &logger)
{
    printf("-------- %s ---- <%s:%d> --------\n", logger.GetFile(), logger.GetFunc(), logger.GetLine());
    return logger;
}

Logger &ValuePrintf(Logger &logger)
{
    printf("\n    \033[31m%s\033[0m<\033[34m%d\033[0m>: value> \033[32m%s\033[0m\n",
           logger.GetFunc(), logger.GetLine(), logger.str().c_str());
    return logger;
}
